import request from '@/utils/request'

export function getTools(data) {
  console.log(data)
  return request({
    url: '/tools/search',
    method: 'get',
    params: data
  })
}

export function getTool(name) {
  return request({
    url: `/toolsbyname/${name}`,
    method: 'get'
  })
}

export function getToolID(id) {
  return request({
    url: `/tools/${id}`,
    method: 'get'
  })
}

export function createTools(data) {
  return request({
    url: '/tools',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

export function updateTools(data) {
  return request({
    url: '/tools',
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

export function deleteTools(id) {
  return request({
    url: `/tools/${id}`,
    method: 'delete'
  })
}

export function retrieveTools(data) {
  console.log(data)
  return request({
    url: '/tools/retrieve',
    method: 'get',
    params: data
  })
}

export function testTool(data) {
  return request({
    url: '/tools/test',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

export function uploadFile(file) {
  return request({
    url: '/tools/file',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
    },
    data: file
  })
}

export function autoRecommendParam(type, params) {
  return request({
    url: `/workflows/customize_parameter`,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
    },
    params: { 'type': type },
    data: params
  })
}



// 定时任务相关
export function getAllEvent() {
  return request({
    url: '/tools/get_all_event',
    method: 'GET',
  })
}
export function addEvent(data) {
  return request({
    url: '/tools/add_event',
    method: 'POST',
    data: data,
  })
}

export function updateEvent(data) {
  console.log(data)
  data = JSON.stringify(data)
  console.log(data)
  return request({
    url: '/tools/update_event',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'  
    },
    data: data,          
  })
}

export function removeEvent(id) {
  return request({
    url: `/tools/remove_event/${id}`,
    method: 'delete',
  })
}

export function startEvent(id) {
  return request({
    url: `/tools/start_event/${id}`,
    method: 'post',
  })
}

export function stopEvent(id) {
  return request({
    url: `/tools/stop_event/${id}`,
    method: 'post',
  })
}
